package com.penta.helper;

import cn.hutool.poi.excel.ExcelWriter;
import org.apache.poi.ss.usermodel.Font;

public class FontBuilder {

    private Font font;

    /**
     * 构造函数，用于创建字体
     */
    public FontBuilder(ExcelWriter writer) {
        this.font = writer.getWorkbook().createFont();
    }

    /**
     * 设置字体颜色
     * @param colorIndex
     * @return
     */
    public FontBuilder setColor(int colorIndex) {
        this.font.setColor((short)colorIndex);
        return this;
    }

    /**
     * 设置是否粗体
     * @param b
     * @return
     */
    public FontBuilder setBold(boolean b) {
        this.font.setBold(b);
        return this;
    }

    /**
     * 设置是否斜体
     * @param b
     * @return
     */
    public FontBuilder setItalic(boolean b) {
        this.font.setItalic(b);
        return this;
    }

    /**
     * 设置字体的高度
     * @param fontHeight
     * @return
     */
    public FontBuilder setFontHeight(int fontHeight) {
        this.font.setFontHeightInPoints((short)fontHeight);
        return this;
    }

    /**
     * 设置字体名称
     * @param fontName
     * @return
     */
    public FontBuilder setFontName(String fontName) {
        this.font.setFontName(fontName);
        return this;
    }

    /**
     * 创建并返回
     * @return
     */
    public Font build() {
        return font;
    }

}
